<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();

    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                      + request.getServerPort() + path ;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>修改菜单信息</title>
<s:include value="../include.jsp"></s:include>
<link rel="stylesheet" type="text/css" href="../css/ztree/demo.css">
<link rel="stylesheet" type="text/css" href="../css/ztree/zTreeStyle/zTreeStyle.css">

<script type="text/javascript" src="<%=basePath%>/js/ztree/jquery.ztree.core-3.3.js"></script>
<script type="text/javascript">

	var setting = {
		view : {
			showIcon : showIconForTree
		},
		data : {
			simpleData : {
				enable : true
			}
		}
	};

	var zNodes = <s:text name="jsonArray"></s:text>;

	function showIconForTree(treeId, treeNode) {
		return !treeNode.isParent;
	};

	$(document).ready(function() {
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	});
	/**
	 * 保存
	 */
	function save() {
		//检验菜单名称
		var menuName = document.getElementById("menuName").value;
		menuName = trimVal(menuName);
		if (menuName == "") {
			alert("检验菜单是必填项");
			return;
		}
		//检验菜单级别，必须是数字1-99
		var menuSeq = document.getElementById("menuSeq").value;
		if (menuSeq != "") {
			menuSeq = trimVal(menuSeq);
			if (isNaN(menuSeq)) {
				alert("菜单级别必须是数字1-99");
				return;
			}
		} else {
			alert("菜单级别是必填项");
			return;
		}
		
		//检验菜单排序
		var menuSort = document.getElementById("menuSort").value;
		if (menuSort != "") {
			menuSort = trimVal(menuSort);
			if (isNaN(menuSort)) {
				alert("菜单排序必须是数字1-99");
				return;
			}
		} else {
			alert("菜单顺序是必填项");
			return;
		}

		chgAction("menuAction", "save");
		document.forms[0].submit();
	}
	
	function initTree() {
		<s:if test="menuForm.menuId!=''">
		//默认选中专业节点
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var node = treeObj.getNodeByParam("id", "<s:property value='menuForm.parentId'/>");
		treeObj.selectNode(node,false);
		</s:if>
	}

	/**
	 * 返回
	 */
	function back() {
		window.location = "menuAction.action";
	}
	<s:if test="operateResult=='suc'">
	alert("保存成功");
	window.location = "menuAction!query.action";
	</s:if>
	<s:elseif test="operateResult=='fail'">
	alert("保存失败");
	</s:elseif>
</script>
</head>
<body onload="initTree()">

	<div class="outerDiv">
		<s:form name="form1" action="menuAction" method="post">
			<s:hidden name="menuForm.menuId"></s:hidden>
			<div class="top_box">
				您的位置：基础功能&gt;&gt;菜单信息管理&gt;&gt;<span class="red">修改菜单信息</span>
			</div>
			<div class="form_list_box">
				<table width="100%">
					<tr>
						<td align="right">父菜单：</td>
						<td>
							<div class="zTreeDemoBackground left" style="height: 250px">
								<ul id="treeDemo" class="ztree" style="height: 230px" disabled="true"></ul>
							</div>
						</td>
					</tr>
					
					<tr>
						<td align="right" width="40%"><font color="red">*</font>菜单名称：</td>
						<td align="left"><s:textfield name="menuForm.menuName"
								id="menuName" maxlength="25"></s:textfield>
						</td>
					</tr>
					<tr>
						<td align="right" width="40%">菜单编号：</td>
						<td align="left"><s:textfield name="menuForm.menuCode"
								id="menuCode" maxlength="6" disabled="true"></s:textfield>
						</td>
					</tr>
					<tr>
						<td align="right" width="40%">菜单级别：</td>
						<td align="left">
							<s:select list="#{0:'请选择',1:'第一级菜单',2:'第二级菜单',3:'第三级菜单',4:'第四级菜单',5:'第五级菜单'}"
								name="menuForm.menuSeq" id="menuSeq"  disabled="true"></s:select>
						</td>
					</tr>
					<tr>
						<td align="right" width="40%"><font color="red">*</font>菜单顺序(0～99)：</td>
						<td align="left"><s:textfield name="menuForm.menuSort"
								id="menuSort" maxlength="2"></s:textfield>
						</td>
					</tr>
				</table>
				<div class="btn_box">
					<a href="#" onclick="save()"><s></s>保存</a> <a href="#"
						onclick="back()"><s></s>返回</a>
				</div>
			</div>
		</s:form>
	</div>
</body>
</html>